<?php

class jornadaActions extends sfActions {

       public function preExecute()
    {
         $this->getUser()->setAttribute('s_menu', 'jornada');
    }

       public function executeVeri(sfWebRequest $request){

               $c=new Criteria();
              $c->add(WorkDaysPeer::FECHA_FIN, date("Y-m-d"), Criteria::GREATER_EQUAL);
              $cont=WorkDaysPeer::doCount($c);
               if($cont>0){
                    $this->redirect('@jornada_active');  
               }
               else{
                    $this->redirect('@jornada_past');
               }
       }

    
    public function executeActive(sfWebRequest $request){

  
        $cod=$request->getParameter('cod');
        $c = new Criteria();
        $events = array();

        $c->clear();
        $c->add(WorkDaysPeer::FECHA_FIN, date("Y-m-d"), Criteria::GREATER_EQUAL);
        $c->addDescendingOrderByColumn(WorkDaysPeer::ORDER);
 
   
            $pager = new sfPropelPager('WorkDays', 14);
            $pager->setCriteria($c);
            $pager->setPage($request->getParameter('page', 1));
            $pager->init();
            $this->pager = $pager;

            $maxpag=$pager->getMaxPerPage();
            $this->max=$maxpag;
            $pagina=$request->getParameter('page',1);
            $this->pagina=$pagina;
            return sfView::SUCCESS;

    }

    public function executePast(sfWebRequest $request){
        $c = new Criteria();
        $events = array();

        $c->clear();
        $c->add(WorkDaysPeer::FECHA_FIN, date("Y-m-d"), Criteria::LESS_THAN);
        $c->addDescendingOrderByColumn(WorkDaysPeer::ORDER);

        $pager = new sfPropelPager('WorkDays',14);
        $pager->setCriteria($c);
        $pager->setPage($request->getParameter('page', 1));
        $pager->init();
        $this->pager = $pager;

        $maxpag=$pager->getMaxPerPage();
        $this->max=$maxpag;
        $pagina=$request->getParameter('page',1);
        $this->pagina=$pagina;
    }

    public function executeDetail(sfWebRequest $request){
       
        $id = $request->getParameter('id');

        $c = new Criteria();
        $c->add(WorkDaysPeer::ID, $id);
        $jornada = WorkDaysPeer::doSelectOne($c);
        if(!is_object($jornada)){
            $this->forward404();
        }

        $this->jornada = $jornada;
    }

        public function executeResolucion(sfWebRequest $request){



        $id = $request->getParameter('id');

        $c = new Criteria();
        $x=new WorkDays();
        $x->getIsSolved();
        $c->add(WorkDaysPeer::ID, $id);
        $c->add(WorkDaysPeer::IS_SOLVED, 1);
        $jornada = WorkDaysPeer::doSelectOne($c);
        if(!is_object($jornada)){
            $this->forward404();
        }

        $this->jornada = $jornada;
    }


}